<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\store\controller;

use app\api\model\BalanceDetail;
use app\api\model\BalanceDetailModel;
use app\api\model\GameModel;
use app\api\model\GradeModel;
use app\api\model\IdentityModel;
use library\Controller;
use think\Db;
use think\facade\Cache;

/**
 * 表单信息管理
 * Class UserInfo
 * @package app\store\controller
 */
class UserInfo extends Controller
{
    /**
     * 指定数据表
     * @var string
     */
    protected $table = 'TeUserinfo';

    /**
     * 表单信息列表管理
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index()
    {

        $this->title = '表单信息列表管理';
        $where = [];
        $params = input();
        $where[] = ['is_handle','eq',$params['type']];
        #关键字搜索
        if (isset($params['keywords']) && $params['keywords'] !== '') {
            $where[] = ['nickname|phone|wechat_num|email|partition|partition_content|week_days|days_time_slot','like',"%{$params['keywords']}%"];
        }


        #注册时间
        if (isset($params['create_time']) && $params['create_time'] !== '') {
            $create_time = explode(' - ',$params['create_time']);
            $create_time1 = $create_time[1].' 23:59:59';
            $where[] = ['create_at','between',"{$create_time[0]},{$create_time1}"];
        }
        $query = $this->_query($this->table);
//        var_dump($query);
        $query->where($where)->order('create_at desc')->page();

    }

    /**
     * 数据列表处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function _index_page_filter(&$data)
    {

        $is_base_device = [0=>'',1=>'无任何设备',2=>'只有电脑',3=>'有配套的基础设备（如耳机，麦克风，普通摄像头等）',4=>'有进阶的设备（如声卡，中高端摄像头等）'];
        $week_days = [0=>'',1=>'四天及一下',2=>'5-7天',3=>'时间不固定',4=>'其他'];
        foreach ($data as  &$v){

            $v['sex'] = $v['sex'] == 0 ? '男' : '女';
            $v['is_live_experience'] = $v['is_live_experience'] == 1 ? '无' : '有';
            $v['live_intention'] = $v['live_intention'] == 1 ? '游戏' : '娱乐';
            $v['is_full_time'] = $v['is_full_time'] == 1 ? '全职' : '兼职';
            $v['expose_plan'] = $v['expose_plan'] == 1 ? '可以露脸' : '不打算露脸但可以开皮套人（虚拟主播）或放自拍照直播';
            $v['is_media_num'] = $v['is_media_num'] == 1 ? '无' : '有';
            $v['is_okmai'] = $v['is_okmai'] == 1 ? '无' : '有';
            $v['is_base_device'] = $is_base_device[$v['is_base_device']];
            $v['week_days'] = $week_days[$v['week_days']];
            $v['partition'] = GameModel::where(['id'=>$v['partition']])->value('name');
            $v['partition_content'] = GameModel::where(['id'=>$v['partition_content']])->value('name');
        }
    }

    /**
     * 表单结果处理
     * @param boolean $result
     */
    protected function _form_result($result)
    {
        if ($result && $this->request->isPost()) {
            $this->success('表单信息操作成功！', 'javascript:history.go()');
        }
    }

    /**
     * 处理表单信息
     * @auth true
     * @menu true
     */
    public function handle(){

        $this->_save($this->table, ['is_handle' => 1]);
    }



}
